package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.commom.exception.Assert;
import com.atguigu.srb.commom.result.R;
import com.atguigu.srb.core.pojo.entity.IntegralGrade;
import com.atguigu.srb.core.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import sun.rmi.runtime.Log;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author lay_hu
 * @since 2021-12-13
 */
@Api(tags = "积分管理")
@Slf4j
//@CrossOrigin
@RestController
@RequestMapping("/admin/core/integralGrade")
public class AdminIntegralGradeController {
    @Resource
    IntegralGradeService integralGradeService;

    @GetMapping("/list")
    @ApiOperation("数据查询")
    public R findAll(){
      log.info("this is  log  ingo");
        log.info("this is  log  error");
        List<IntegralGrade> list = integralGradeService.list();
        return  R.ok().data("list",list).message("获取列表成功");
    }

    @DeleteMapping("removeById/{id}")
    public  R removeById(@PathVariable Long id){
        boolean b = integralGradeService.removeById(id);
        if (b){
            return R.ok().message("删除成功");
        }else {
            return R.error().message("删除失败");
        }

    }
    @ApiOperation("新增积分等级")
    @PostMapping("/save")
    public  R save(
            @ApiParam(value = "积分等级对象",required = true)
            @RequestBody IntegralGrade integralGrade){
        boolean save = integralGradeService.save(integralGrade);
        if (save){
            return  R.ok().message("新增积分成功");
        }else {
            return R.error().message("新增积分失败");
        }

    }
    @ApiOperation("根据id获取积分等级")
    @GetMapping("/get/{id}")
    public  R getById(@PathVariable Long id){
        IntegralGrade integralGrade = integralGradeService.getById(id);
     if (integralGrade !=null){
         return R.ok().data("integralGrade",integralGrade);
     }else {
         return R.error().message("获取失败");
     }
    }
}

